package com.swust.servlet;

import com.swust.service.LibServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "ToAddBookServlet",urlPatterns = "/ToAddBookServlet")
public class ToAddBookServlet extends HttpServlet {
    private LibServiceImpl libService = new LibServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Map<String, Object>> bookClass = libService.getBookCatgory();
        // 将存在多条数据的list集合保存到request中
        request.setAttribute("lists", bookClass);
        // 将addBook.jsp中取出request中的list集合
        request.getRequestDispatcher("/view/addBook.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
